<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="db.OutreqDAO"%>
<%@page import="db.OutpurmatDAO"%>
<%@page import="db.Outreq"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="db.TobDAO"%>
<%@page import="db.Tob"%>
<%@page import="db.TeamDAO"%>
<%@page import="db.Team"%>
<%@page import="db.CompanyDAO"%>
<%@page import="db.Company"%>
<%@page import="db.ReccompanyDAO"%>
<%@page import="db.Reccompany"%>
<%@page import="db.BormatDAO"%>
<%@page import="db.BorreqDAO"%>
<%@page import="db.Borreq"%>
<%@ include file="/jsp/common/utility/volti.jsp" %>
<%@ include file="/jsp/common/utility/logined.jsp" %>

<%
	WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	BorreqDAO borreqDao = (BorreqDAO)ctx.getBean("BorreqDAO");
	BormatDAO bormatDao = (BormatDAO)ctx.getBean("BormatDAO");
	UserDAO userDao = (UserDAO)ctx.getBean("UserDAO");
	TobDAO tobDao = (TobDAO)ctx.getBean("TobDAO");
	TeamDAO teamDao = (TeamDAO)ctx.getBean("TeamDAO");
	CompanyDAO companyDao = (CompanyDAO)ctx.getBean("CompanyDAO");
	ReccompanyDAO recompanyDao = (ReccompanyDAO)ctx.getBean("ReccompanyDAO");
	
	int tid = (Integer)session.getAttribute("tid");
	int uid = (Integer)session.getAttribute("id");
	
	String idPar = request.getParameter("id");
	int id = 0;
	
	try{
		id = Integer.parseInt(idPar);
	}catch(Exception e){
		id = 0;
	}
	
	List tobs = tobDao.findAll();
	for(int i=0;i<tobs.size();i++){
		Tob tob = (Tob)tobs.get(i);
		if("还库".equals(tob.getName())){
			request.setAttribute("tob",tob);
			break;
		}
	}
	
	Borreq borreq = borreqDao.findById(id);
	request.setAttribute("borreq",borreq);
	
	List outpurmats = bormatDao.findByBorreqIdAndState(borreq.getId(),3);
	request.setAttribute("outpurmats",outpurmats);
	
	User reqUser = userDao.findById(borreq.getReqUserId());
	request.setAttribute("reqUser",reqUser);
	
	request.setAttribute("users",userDao.findAll());
	
	Team team = teamDao.findById(borreq.getTeamId());
	request.setAttribute("team",team);
	
	Company company = companyDao.findById(borreq.getCompanyId());
	request.setAttribute("company",company);
	
	Reccompany reccompany = recompanyDao.findById(borreq.getReccompanyId());
	request.setAttribute("reccompany",reccompany);
	
	User retUser = userDao.findById(uid);
	request.setAttribute("retUser",retUser);
	
	Team retTeam = teamDao.findById(tid);
	request.setAttribute("retTeam",retTeam);
	
	pageContext.forward("/vm/borrowStock/borrowApp_1_1_1.vm");
%>